﻿#include "../../libcat/include/cat-module.hpp"
#include "../../libcat/include/header/cat-config.hpp"
#include "NotificationIcon.hpp"

namespace {
	static bool ui_key_event[3] = { false };
}

void* KeyPress(const cat_key_event* event, bool key_up) {

	switch (event->native_vkey)
	{
		case 0x10:
			if(key_up)
				ui_key_event[0] = false;
			else
				ui_key_event[0] = true;
			break;
		case 0x11:
			if (key_up)
				ui_key_event[1] = false;
			else
				ui_key_event[1] = true;
			break;
		case 0x53:
			if (key_up)
				ui_key_event[2] = false;
			else
				ui_key_event[2] = true;
			break;
		default:
			break;
	}

	return NULL;
};

void* Init(cat_data_t* settings) {
	NotificationIcon::GetInstance()->Start();
	return NULL;
}

void* Release() {
	NotificationIcon::GetInstance()->Stop();
	return NULL;
};

void* Run(void* _window) {
	
	cat_window* cwindow = (cat_window*)_window;
	if ( ui_key_event[0]
		&& ui_key_event[1]
		&& ui_key_event[2]
		&& cwindow->window->hasFocus()) {
		NotificationIcon::GetInstance()->OnStartUi();
	}
	
	return _window;
};

CAT_DECLARE_MODULE()
bool cat_module_load (){
	cat_source_info a {};
	a.id = 0;
	a.type = CAT_SOURCE_TYPE_UI;
	a.Init = Init;
	a.Release = Release;
	a.Run = Run;
	a.OnKeyPress = KeyPress;

	cat_register_source(&a);
	return true;
}
